package com.bulletelc.apollopre.module.display.search;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.bulletelc.apollopre.R;

import java.util.List;

/**
 * Created by CX on 2018/4/8.
 */

public class HistoryAdapter extends BaseAdapter {

    private Context context;
    private List<String> listData;
    private LayoutInflater inflater;

    public HistoryAdapter(Context context, List<String> listData) {
        this.context = context;
        this.listData = listData;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return listData.size();
    }

    @Override
    public Object getItem(int i) {
        if (listData.size() >0 && listData != null) {
            return listData.get(i);
        }
        return 0;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (view == null) {
            view = inflater.inflate(R.layout.search_list_item, viewGroup, false);
            viewHolder = new ViewHolder();
            viewHolder.tvLabel = view.findViewById(R.id.tvLabel);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        viewHolder.tvLabel.setText(listData.get(i).toString());
        return view;
    }

    class ViewHolder {
        TextView tvLabel;
    }
}
